<?php
//No direct access
defined('_JEXEC') or die('Restricted access');
?>
<div id="ownservices">
 <div id="mainmenuownservice"><?php echo MenuHelper::nav(); ?></div>
	<div id="mainownservice">
		<h3><?php echo $this->params->def('page_title'); ?></h3>
		<hr />
		<form name="adminForm" method="post" action="<?php echo JRoute::_('index.php?option=com_ownservice'); ?>">
			<table>
				<tr>
					<td><?php echo JText::_('OWNSERVICE_REQUESTED_DATE_TIME'); ?> :</td>
					<td>
						<?php
							list($date, $time) = @explode(' ', @$this->rows[0]->requested_date);
							echo $this->reportdate.' '.$time; 
						?>
					</td>
				</tr>
				<tr>
					<td>Session :</td>
					<td><?php echo $this->session; ?></td>
				</tr>
			</table>
			<table class="adminlist" cellspacing="1">
				<tr>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_RECEIVER_NO'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_ACCOUNT_NO'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_USER'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_BANK_NAME'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_BRANCH_CITY'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_REQUESTED_DATE_TIME'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_AMOUNT_TRANSFER'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_RATE'); ?>
					</td>
					<td align="center" class="tablelist">
						<?php echo JText::_('OWNSERVICE_TOTAL_EXCHANGE'); ?>
					</td>
				</tr>
				<?php
					$k 			 	= 0;
					$total		 		= 0;
					$sum_amount	= 0;
					$sum_rate	 	= 0;
					$sum_total		= 0;
					$priceformat 	= OwnserviceHelper::getParams('price_format', '#,###.##');
					$dateformat  	= OwnserviceHelper::getParams('date_format', '%d/%m/%Y'); 
					for($i=0,$n=count($this->rows);$i<$n;$i++):
					
					$row = $this->rows[$i];
				?>
				<tr class="<?php echo "row$k"; ?>">
					<td align="center" class="inner_tablelist">
						<?php echo $row->invoice; ?>
					</td>
					<td align="center" class="inner_tablelist">
						<?php echo OwnserviceHelper::accountFormat($row->account); ?>
					</td>
					<td class="inner_tablelist">
						<?php echo $row->username; ?>
					</td>
					<td class="inner_tablelist">
						<?php echo $row->bank_name; ?>
					</td>
					<td class="inner_tablelist"> 
						<?php echo $row->branch_city; ?>	
					</td>
					<td class="inner_tablelist" align="center">
						<?php echo JHTML::_('date', $row->requested_date, $dateformat); ?>
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php 
							echo OwnserviceHelper::moneyFormat($priceformat,$row->amount); 
							$sum_amount = $sum_amount + $row->amount;
						?> AUD
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php
							$color = '';
							if($row->extrarate > 0.00 ) {
								$color = 'red';
							} else if($row->extrarate < 0.00) {
								$color = 'green';
							}
						?>
						<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px dotted #ccc;">
								<?php 
									echo OwnserviceHelper::moneyFormat($priceformat,$row->rate_th);
									$sum_rate = $sum_rate + $row->rate_th; 
								?> THB
							</div>
						<?php
							else:
								$sum_rate = $sum_rate + ($row->rate+$row->extrarate);  
							endif; 
						?>
						<div class ="<?php echo $color; ?>">
							<?php 
								echo OwnserviceHelper::moneyFormat($priceformat,$row->rate+$row->extrarate).' '.$row->rate_code; 
							?> 
						</div>
					</td>
					<td class="inner_tablelist" align="right" nowrap="nowrap">
						<?php 
							/* total transfer */
							$color = '';
							if($row->extratotal > 0.00 ){
								$color = 'red';
								$total = $row->extratotal;	
							} else {
								$total = ( ( $row->amount * ($row->rate+$row->extrarate) ) - ($row->bankfee+$row->extrabfee) );
							}
						?>
						<?php if(!$row->iscore): ?>
							<div style="border-bottom: 1px dotted #ccc;">
								<?php 
									echo OwnserviceHelper::moneyFormat($priceformat,$row->total_th);
									$sum_total = $sum_total + $row->total_th;
								?> THB
							</div>
						<?php
							else:
								$sum_total = $sum_total + $total;  
							endif; 
						?>
						<div class="<?php echo $color; ?>">
							<?php echo OwnserviceHelper::moneyFormat($priceformat,$total).' '.$row->rate_code;; ?>
						</div> 
					</td>
				</tr>
				<?php $k = 1 - $k; endfor; ?>
				<tr>
					<td colspan="6" align="right">
						<strong><?php echo JText::_('OWNSERVICE_TOTAL'); ?></strong>
					</td>
					<td align="right">
						<strong><?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_amount).' AUD'; ?></strong>
					</td>
					<td align="right" style="font-weight: bold;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_rate). ' THB'; ?>
					</td>
					<td align="right" style="font-weight: bold;">
						<?php echo OwnserviceHelper::moneyFormat($priceformat,$sum_total). ' THB'; ?>
					</td>
				</tr>
				</tbody>
			</table>
			<input type="hidden" name="id" value="" />
			<input type="hidden" name="date" value="<?php echo $this->reportdate; ?>" />
			<input type="hidden" name="session" value="<?php echo $this->session; ?>" />
			<input type="hidden" name="option" value="com_ownservice" />
			<input type="hidden" name="task" value="reporttransfer" />
			<input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid'); ?>" />
			<input type="hidden" name="controller" value="reporttransfer" />
			<input type="hidden" name="view" value="reporttransfer" />
			<?php echo JHTML::_( 'form.token' ); ?>
		</form>
	</div>
</div>